package com.omazan.nativeClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.omazan.db.HandleAdmins;
import com.omazan.db.HandleCustomers;
import com.omazan.db.HandleEmployees;
import com.omazan.db.HandleUsers;
import com.omazan.db.models.Customer;
import com.omazan.utils.OmazanException;

import com.omazan.db.models.Administrator;
import com.omazan.db.models.Employee;
import com.omazan.db.models.User;

public class UserAddOperations {

	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	
	public int userAddLogin(int type) throws OmazanException, IOException{
		
		User user = new User();
		
		System.out.println("Enter User name");
		user.setUserName(input.readLine());
		System.out.println("Enter User password");
		user.setPassword(input.readLine());
		
		user.setActive(true);
		user.getUserType().setUserTypeId(type);
		
		new HandleUsers().insertUser(user);
		//System.out.println(user.getUserId());
		return user.getUserId();
	}
	
	public void usertypeAddOperations() throws OmazanException, IOException
	{
		int m=0;
		while(m==0)
		{
		System.out.println("ADD:");
		System.out.println("1.Customer");
		System.out.println("2.Employee");
		System.out.println("3.Administrator");
		System.out.println("4.Exit to Previous Menu");
		String userInput = input.readLine();
		int operation = Integer.parseInt(userInput);
		switch(operation)
		{
		case 1:
			
			Customer cust1 = new Customer();
			cust1.getUser().setUserId(userAddLogin(3));
			System.out.println("Enter Customer First Name:");
			String str;
			str=input.readLine();
			cust1.setFirstName(str);
			System.out.println("Enter Customer Last Name:");
			str=input.readLine();
			cust1.setLastName(str);
			System.out.println("Enter Customer House No:");
			str=input.readLine();
			cust1.setHouseNo(str);
			System.out.println("Enter Customer Street:");
			str=input.readLine();
			cust1.setStreet(str);
			System.out.println("Enter Customer City:");
			str=input.readLine();
			cust1.setCity(str);
			System.out.println("Enter Customer State:");
			str=input.readLine();
			cust1.setState(str);
			System.out.println("Enter Customer Country:");
			str=input.readLine();
			cust1.setCountry(str);
			System.out.println("Enter Customer Email:");
			str=input.readLine();
			cust1.setEmail(str);
			System.out.println("Enter Customer Mobile No:");
			str=input.readLine();
			cust1.setMobileNo(str);			
			HandleCustomers hcust1 = new HandleCustomers();
			hcust1.insertCustomer(cust1);
			break;
		case 2:
			Employee emp1 = new Employee();
			emp1.getUser().setUserId(userAddLogin(2));
			System.out.println("Enter Employee First Name:");
			String stre;
			stre=input.readLine();
			emp1.setFirstName(stre);
			System.out.println("Enter Employee Last Name:");
			stre=input.readLine();
			emp1.setLastName(stre);
			System.out.println("Enter Employee House No:");
			stre=input.readLine();
			emp1.setHouseNo(stre);
			System.out.println("Enter Employee Street:");
			stre=input.readLine();
			emp1.setStreet(stre);
			System.out.println("Enter Employee City:");
			stre=input.readLine();
			emp1.setCity(stre);
			System.out.println("Enter Employee State:");
			stre=input.readLine();
			emp1.setState(stre);
			System.out.println("Enter Employee Country:");
			stre=input.readLine();
			emp1.setCountry(stre);
			System.out.println("Enter Employee Email:");
			stre=input.readLine();
			emp1.setEmail(stre);
			System.out.println("Enter Employee Mobile No:");
			stre=input.readLine();
			emp1.setMobileNo(stre);			
			HandleEmployees hemp1 = new HandleEmployees();
			hemp1.insertEmployee(emp1);
			break;
			
		case 3:
			Administrator adm1 = new Administrator();
			adm1.getUser().setUserId(userAddLogin(1));
			System.out.println("Enter Administrator First Name:");
			String stra;
			stra=input.readLine();
			adm1.setFirstName(stra);
			System.out.println("Enter Administrator Last Name:");
			stra=input.readLine();
			adm1.setLastName(stra);
			System.out.println("Enter Administrator House No:");
			stra=input.readLine();
			adm1.setHouseNo(stra);
			System.out.println("Enter Administrator Street:");
			stra=input.readLine();
			adm1.setStreet(stra);
			System.out.println("Enter Administrator City:");
			stra=input.readLine();
			adm1.setCity(stra);
			System.out.println("Enter Administrator State:");
			stra=input.readLine();
			adm1.setState(stra);
			System.out.println("Enter Administrator Country:");
			stra=input.readLine();
			adm1.setCountry(stra);
			System.out.println("Enter Administrator Email:");
			stra=input.readLine();
			adm1.setEmail(stra);
			System.out.println("Enter Administrator Mobile No:");
			stra=input.readLine();
			adm1.setMobileNo(stra);			
			HandleAdmins hadm1 = new HandleAdmins();
			hadm1.insertAdmin(adm1);
			break;
		case 4:
			m++;
			System.out.println("");
			break;
			default:
				break;
		}
		
	}
}
}